﻿

Imports System.IO
Imports System.Net
Imports System.Net.Mail
Public Class Internet

    Dim int As Integer = 0
    Dim sp1 = 1

    Private Sub texteingabe_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
        If e.KeyValue = 13 Then  'Eingabetaste

            navi("http://www.google.de/#hl=de&q=" & TextBox2.Text.Replace(" ", "+"))
       

        End If
    End Sub

    Private Sub texteingabe2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
        If e.KeyValue = 13 Then  'Eingabetaste

            navi(ComboBox1.Text)










        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Refresh()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).GoBack()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).GoForward()
    End Sub


    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
        Me.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Document.Title
        ComboBox1.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString






    End Sub

   
   
    

    Dim full, drive As String
    Dim urlold

    
    Dim online

    Private Sub Internet_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BackgroundWorker1.WorkerSupportsCancellation = True
        BackgroundWorker1.RunWorkerAsync()
        Dim Browser As New WebBrowser
        Browser.Name = "Web Browser"
        Browser.Dock = DockStyle.Fill
        Browser.Navigate("www.google.de")
        TabControl1.SelectedTab.Controls.Add(Browser)
        int = int + 1

        navi("http://www.google.de")
        full = Reflection.Assembly.GetExecutingAssembly.Location
        drive = IO.Path.GetPathRoot(full)
        Try

            Dim index1 = System.IO.File.ReadAllLines("" & drive & "Cyberweb.fav").Length
            Dim lines() As String = IO.File.ReadAllLines("" & drive & "Cyberweb.fav")
            Dim ik = index1
            Dim i
            For i = 1 To ik

                index1 = ik - i

                If (lines(index1)).Replace(" ", "") = "" Then
                Else
                    newtab(lines(index1))
                End If



            Next i
        Catch
        End Try
        Try
            ComboBox1.Items.Clear()
            Dim index1 = System.IO.File.ReadAllLines("" & drive & "Cyberweb.log").Length
            Dim lines() As String = IO.File.ReadAllLines("" & drive & "Cyberweb.log")
            Dim ik = index1
            Dim i
            For i = 1 To 50

                index1 = ik - i
                ComboBox1.Items.Add(lines(index1))


            Next i
        Catch
        End Try

    End Sub


    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        navi(ComboBox1.Text)

    End Sub


    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Form2.Show()
    End Sub

    Private Sub TextBox2_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.MouseEnter
        If sp1 = 1 Then
            TextBox2.Text = ""
            sp1 = 0
        End If
    End Sub







    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

        Select Case MessageBox.Show("Neues Lesezeichen?" & vbNewLine + "JA = Neus Lesezeichen!" & vbNewLine + "Nein = Lesezeichen Liste Öffnen!", "Neues Lesezeichen?", MessageBoxButtons.YesNo)
            Case Windows.Forms.DialogResult.Yes
                Dim inputString As String = vbNewLine + CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString
                My.Computer.FileSystem.WriteAllText("" & drive & "Cyberweb.fav", inputString, True)

            Case Windows.Forms.DialogResult.No
                Form3.Show()
        End Select


    End Sub












    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        navi("http://www.google.de/#hl=de&q=" & TextBox2.Text.Replace(" ", "+"))
    End Sub


    Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow


        e.Cancel = True ' Neues Fenster blocken
    End Sub

    Public Sub newtab(ByVal url)

        Dim Browser As New WebBrowser
        TabControl1.TabPages.Add("New Page")
        TabControl1.SelectTab(int)
        Browser.Name = "Web Browser"
        Browser.Dock = DockStyle.Fill
        TabControl1.SelectedTab.Controls.Add(Browser)
        int = int + 1
        AddHandler Browser.Navigated, AddressOf WebBrowser1_Navigated
        AddHandler Browser.Navigating, AddressOf WebBrowser1_Navigating
        AddHandler Browser.NewWindow, AddressOf WebBrowser1_NewWindow

        AddHandler Browser.DocumentCompleted, AddressOf WebBrowser1_DocumentCompleted
        navi(url)
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        newtab("www.google.de")
    End Sub


    Public Sub navi(ByVal URL1)
        CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Navigate(URL1)
        Me.TopMost = False
        load1.Show()
        Do While CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).ReadyState <> WebBrowserReadyState.Complete
            Application.DoEvents()
        Loop
        load1.Hide()
        Me.TopMost = True

    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If Not TabControl1.TabPages.Count = 1 Then
            TabControl1.TabPages.RemoveAt(TabControl1.SelectedIndex)
            TabControl1.SelectTab(TabControl1.TabPages.Count - 1)
            int = int - 1
        End If
    End Sub

    Private Sub WebBrowser1_Navigated(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated

        TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle

        ComboBox1.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString
    End Sub

    Private Sub WebBrowser1_Navigating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating


        CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).ScriptErrorsSuppressed = True
        If urlold = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString Then
        Else
            Dim inputString As String = vbNewLine + CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString
            My.Computer.FileSystem.WriteAllText("" & drive & "Cyberweb.log", inputString, True)
            urlold = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).Url.ToString
            Try
                ComboBox1.Items.Clear()
                Dim index1 = System.IO.File.ReadAllLines("" & drive & "Cyberweb.log").Length
                Dim lines() As String = IO.File.ReadAllLines("" & drive & "Cyberweb.log")
                Dim ik = index1
                Dim i
                For i = 1 To 50

                    index1 = ik - i
                    ComboBox1.Items.Add(lines(index1))


                Next i
            Catch
            End Try

        End If

    End Sub

   
    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Application.DoEvents()
        Dim allProcesses As Process() = Process.GetProcesses()
        Dim p As Process = Nothing
        Dim i As Integer
        Dim processName As String = ("iexplore")

        For i = 0 To UBound(allProcesses)
            If allProcesses(i).ProcessName = processName Then
                p = allProcesses(i)
                Exit For
            End If
        Next
        Application.DoEvents()
        If p Is Nothing Then

        Else
            Dim proc As System.Diagnostics.Process
            Dim pList() As Process

            pList = Process.GetProcessesByName("iexplore")
            For Each proc In pList
                proc.Kill()
            Next
        End If
        Application.DoEvents()
    End Sub

    Private Sub Internet_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        BackgroundWorker1.CancelAsync()
    End Sub
End Class


